package com.yanqu.road.server.cmd.activity.advertisement;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.AdvertisementProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.advertisement.AdvertisementActivityModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ADVERTISEMENT_ACTIVITY_WATCH_OVER,desc = "广告活动观看结束领奖")
public class AdvertisementWatchingOverCmd extends AbstractCommand {

    private int activityId;
    private int systemId;
    private long overTime;
    private int isSkip;
    private int param;


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        AdvertisementProto.WatchAdvertisementOverReqMsg reqMsg = AdvertisementProto.WatchAdvertisementOverReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        systemId = reqMsg.getId();
        overTime = reqMsg.getOverTime();
        isSkip = reqMsg.getIsSkip();
        if (reqMsg.hasParam()){
            param = reqMsg.getParam();
        }else {
            param = 0;
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        AdvertisementProto.WatchAdvertisementOverRespMsg.Builder builder = player.getModule(AdvertisementActivityModule.class).watchAdOver(activityId, systemId, overTime, isSkip, param);
        player.sendPacket(ClientProtocol.U_ADVERTISEMENT_ACTIVITY_WATCH_OVER,builder);
    }

    @Override
    public void sendData(GamePlayer player) {
//        if (ret != 0){
//            AdvertisementProto.WatchAdvertisementOverRespMsg.Builder builder = AdvertisementProto.WatchAdvertisementOverRespMsg.newBuilder();
//            builder.setRet(ret);
//            player.sendPacket(ClientProtocol.U_ADVERTISEMENT_ACTIVITY_WATCH_OVER,builder);
//        }
    }
}
